<template>
  <van-nav-bar
      title="紫贝记录"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
  />
<div class="dv1">
  <van-tabs v-model:active="activeName">
    <van-tab title="消费记录" name="a">
      <van-list
          v-model:loading="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
      >
        <van-swipe-cell  v-for="log in moneyLogs" >
          <van-cell  :title="log.info" :label="log.ctime" :value="log.type === 1 ? '+' + log.money : '-' + log.money" />
        </van-swipe-cell>
      </van-list>
    </van-tab>
    <van-tab title="充值记录" name="b">
      <van-list
          v-model:loading="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
      >
        <van-swipe-cell  v-for="log in payLogs" >
          <van-cell :title="log.title" :value="log.status === 2 ? '+' + log.money : '未支付金额'+ log.money" :label="log.ctime" />
        </van-swipe-cell>
      </van-list></van-tab>
  </van-tabs>
</div>
</template>

<script setup>
import {ref, vShow} from "vue";
import {get} from "../util/request.js";
import {showToast} from "vant";

const moneyLogs = ref([]);

const payLogs = ref([]);
const loading = ref(false);
const finished = ref(false);
// 配置异步请求刷新的方法
const moneyLogList = () => {
      get('user/moneyLog' ).then( r=>{
    loading.value = false;
    if (r.code == 0){ // 获取成功
      // alert("查询成功")
      moneyLogs.value= r.data;
      finished.value = true;
    }else {
      showToast("查询失败")
      // 加载状态结束
    }
  }).catch(function (){
    alert("服务器异常")
  });
}
//
const payLogList = () => {
  get('user/payLog' ).then(r =>{
    if (r.code == 0){ // 获取成功
      // alert("查询成功")
      payLogs.value= r.data;
      finished.value = true;
    }else {
      showToast("查询失败")
      finished.value = true;
      // 加载状态结束
    }
  }).catch(function (){
    alert("服务器异常")
  });
}
const onLoad = () => {
  // 发起axios 请求 刷新
  moneyLogList();
  payLogList();
};
const onClickLeft = () => history.back();
const activeName=ref('a')
</script>
<style scoped>
.dv1{

}
</style>